package com.example.demo;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: 公众号:干货食堂
 * Project Name: springboot-mybatis-demo2
 * File Name: GeneratorTest
 * Package Name: com.example.demo
 * Date: 2023/7/13 23:02
 * Copyright (c) 2023,All Rights Reserved.
 * @Description
 */
public class GeneratorTest {
    public static void main(String[] args) throws Exception {
        List<String> warnings = new ArrayList<>();
        //generatorConfig.xml所在的位置，相对路径和绝对路径都可以。
        File configFile = new File("src/main/resources/generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
        for (String warning : warnings) {
            System.err.println(">" + warning);
        }
    }
}
